home *** CD-ROM | disk | FTP | other *** search
/ Champak 125 / Vol 125 (Damaged).iso / games / rabbit_r.swf / scripts / __Packages / disney / rabbitRivalry / Engine.as < prev    next >
Encoding:
Text File  |  2009-06-09  |  6.1 KB  |  249 lines

  1. class disney.rabbitRivalry.Engine extends MovieClip
  2. {
  3.    var __gameStartTime;
  4.    var __dogePath;
  5.    var __interval;
  6.    var __sounds;
  7.    var viewport_mc;
  8.    var __state;
  9.    var __UI;
  10.    var activeWorld;
  11.    var isPaused;
  12.    var doge_container;
  13.    var isUILocked;
  14.    var __updateUI;
  15.    var mouse;
  16.    var owner;
  17.    var mouseHD_mc;
  18.    var key;
  19.    var __TOTAL_LEVELS = 5;
  20.    var __STARTLEVEL = 1;
  21.    var __DOGE_PATH = "http://atv.disney.go.com/jetix/media/global/scoredisplays/fsd.swf";
  22.    function Engine()
  23.    {
  24.       super();
  25.    }
  26.    function init()
  27.    {
  28.       this.__gameStartTime = getTimer();
  29.       if(_level0.fsd == undefined)
  30.       {
  31.          this.__dogePath = this.__DOGE_PATH;
  32.       }
  33.       else
  34.       {
  35.          this.__dogePath = _level0.fsd;
  36.       }
  37.       this.__interval = new smashing.IntervalEngine(this,"update");
  38.       this.__interval.startFast();
  39.       disney.rabbitRivalry.Sounds.init();
  40.       this.__sounds = disney.rabbitRivalry.Sounds.getInstance();
  41.       this.__sounds.generateSounds(this.viewport_mc);
  42.       disney.rabbitRivalry.GameState.init();
  43.       this.__state = disney.rabbitRivalry.GameState.getInstance();
  44.       this.__state.reset();
  45.       disney.rabbitRivalry.ui.UI.init();
  46.       this.__UI = disney.rabbitRivalry.ui.UI.getInstance();
  47.       this.__UI.linkEngine(this);
  48.       this.__UI.reset();
  49.       disney.rabbitRivalry.Dimensions.init();
  50.       smashing.keithm.Messenger.registerAddress("engine",this);
  51.       smashing.keithm.Viewport.init(this.viewport_mc,2,disney.rabbitRivalry.Dimensions.getInstance());
  52.       var _loc2_ = smashing.keithm.Viewport.getInstance();
  53.       _loc2_.setScrollport(1);
  54.       _loc2_.createGroup({name:"bg",index:0,slots:10,scrollport:true});
  55.       _loc2_.createGroup({name:"trees",index:1,slots:50,reverse:true});
  56.       _loc2_.createGroup({name:"ents",index:2,slots:500});
  57.       _loc2_.createGroup({name:"player",index:3,slots:10});
  58.       _loc2_.createGroup({name:"effect",index:4,slots:500});
  59.       _loc2_.reset();
  60.       this.activeWorld = new disney.rabbitRivalry.World(this);
  61.       this.__initMouse();
  62.       this.__initKey();
  63.       this.pause();
  64.       this.__UI.goScreen("splash");
  65.       this.__sounds.queueSound("yinyangyo");
  66.       this.__sounds.queueSound("splash",true);
  67.    }
  68.    function update(dt)
  69.    {
  70.       if(!this.isPaused)
  71.       {
  72.          this.activeWorld.update(dt);
  73.       }
  74.       this.__UI.update(dt);
  75.       updateAfterEvent();
  76.    }
  77.    function startGame()
  78.    {
  79.       trace("START GAME");
  80.       this.__state.reset();
  81.       this.startLevel();
  82.       this.__sounds.playMusic("game");
  83.    }
  84.    function startLevel()
  85.    {
  86.       this.__UI.goScreen("gameplay");
  87.       this.activeWorld.generate(this.__state.levelNum);
  88.       smashing.keithm.Viewport.getInstance().newView();
  89.       this.activeWorld.start();
  90.       this.unlockUI();
  91.       this.unpause();
  92.    }
  93.    function onEndLevel()
  94.    {
  95.       if(this.__state.levelNum == this.__state.TOTAL_LEVELS)
  96.       {
  97.          this.__sounds.stopMusic();
  98.          this.__UI.goScreen("winGame");
  99.       }
  100.       else
  101.       {
  102.          this.__UI.goScreen("winLevel");
  103.       }
  104.    }
  105.    function onNextLevel()
  106.    {
  107.       this.__state.levelNum = this.__state.levelNum + 1;
  108.       this.__state.removeMiss();
  109.       this.__state.restartState();
  110.       this.__state.toggleRabbit();
  111.       this.startLevel();
  112.       smashing.keithm.Messenger.sendMessage("screen","onNextRabbit");
  113.    }
  114.    function onGameOver()
  115.    {
  116.       this.__UI.goScreen("gameOver");
  117.    }
  118.    function onStartOver()
  119.    {
  120.       this.__UI.goScreen("splash");
  121.       this.__sounds.playMusic("splash");
  122.       this.__state.reset();
  123.       this.clear();
  124.    }
  125.    function onQuit()
  126.    {
  127.       stopAllSounds();
  128.       this.destroy();
  129.    }
  130.    function onHighscore()
  131.    {
  132.       this.pause();
  133.       this.gotoAndStop("highscore");
  134.       System.security.allowDomain("apsc.disney.go.com");
  135.       _level0.eventID = "jetix_yyy_rr";
  136.       _level0.subject = "Yin Yang Yo - Rabbit Rivalry";
  137.       _level0.playerScore = this.__state.score;
  138.       _level0.fsdPlayAgain = mx.utils.Delegate.create(this,this.onStartOver);
  139.       this.doge_container.loadMovie(this.__dogePath);
  140.    }
  141.    function clear()
  142.    {
  143.       this.activeWorld.clear();
  144.       smashing.keithm.Viewport.getInstance().newView();
  145.    }
  146.    function destroy()
  147.    {
  148.       this.__interval.clear();
  149.       this.__clearMouse();
  150.       this.__clearKey();
  151.    }
  152.    function pause()
  153.    {
  154.       this.isPaused = true;
  155.    }
  156.    function unpause()
  157.    {
  158.       this.isPaused = false;
  159.    }
  160.    function lockUI()
  161.    {
  162.       this.isUILocked = true;
  163.    }
  164.    function unlockUI()
  165.    {
  166.       this.isUILocked = false;
  167.    }
  168.    function requestUpdateUI()
  169.    {
  170.       this.__updateUI = true;
  171.    }
  172.    function showHelp()
  173.    {
  174.       this.__UI.goScreen("help");
  175.    }
  176.    function __initMouse()
  177.    {
  178.       this.mouse = {};
  179.       this.mouse.owner = this;
  180.       this.mouse.onMouseUp = function()
  181.       {
  182.          this.owner.mouse_up();
  183.       };
  184.       this.mouse.onMouseDown = function()
  185.       {
  186.          this.owner.mouse_down();
  187.       };
  188.       Mouse.addListener(this.mouse);
  189.    }
  190.    function __clearMouse()
  191.    {
  192.       Mouse.removeListener(this.mouse);
  193.    }
  194.    function mouse_up()
  195.    {
  196.       if(this.isPaused)
  197.       {
  198.       }
  199.    }
  200.    function mouse_down()
  201.    {
  202.       if(!this.isPaused)
  203.       {
  204.          if(this.mouseHD_mc.hitTest(this._xmouse,this._ymouse,true))
  205.          {
  206.             this.activeWorld.onMouseDown();
  207.          }
  208.       }
  209.    }
  210.    function __initKey()
  211.    {
  212.       this.key = {};
  213.       this.key.owner = this;
  214.       this.key.onKeyDown = function()
  215.       {
  216.          this.owner.key_down();
  217.       };
  218.       Key.addListener(this.key);
  219.    }
  220.    function __clearKey()
  221.    {
  222.       Key.removeListener(this.key);
  223.    }
  224.    function key_down()
  225.    {
  226.       if(Key.getCode() == 32)
  227.       {
  228.       }
  229.    }
  230.    function key_up()
  231.    {
  232.       if(!Key.getCode(32))
  233.       {
  234.       }
  235.    }
  236.    function onMessageReceived(message, args)
  237.    {
  238.       this[message](args);
  239.    }
  240.    function get gameStartTime()
  241.    {
  242.       return this.__gameStartTime;
  243.    }
  244.    function isMusicMuted()
  245.    {
  246.       return this.__sounds.muteMusic;
  247.    }
  248. }
  249.